import cv2
from matplotlib import pyplot as plt  # 需要安装matplotlib库

# author: 徐锐
# 直方图创建


class Histogram:
    # 请不要对此函数导入单通道图片
    @staticmethod
    def image_hist(image):
        color = ('blue', 'green', 'red')
        for i, color in enumerate(color):
            hist = cv2.calcHist([image], [i], None, [256], [0, 256])
            plt.plot(hist, color=color)
            plt.xlim([0, 256])
        plt.show()


# 测试
if __name__ == "__main__":
    img = cv2.imread("5.jpg")
    Histogram.image_hist(img)
